package com.stylefeng.guns.rest.common.persistence.dao;

import com.stylefeng.guns.api.film.FilmDetailVo;
import com.stylefeng.guns.rest.common.persistence.model.MoocFilmT;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * <p>
 * 影片主表 Mapper 接口
 * </p>
 *
 * @author zhaoluowei
 * @since 2019-09-13
 */
@Mapper
@Repository(value = "moocFilmTMapper")
public interface MoocFilmTMapper extends BaseMapper<MoocFilmT> {


    @Select("SELECT \n" +
            "\t\tcinema.uuid AS filmId,\n" +
            "\t\tcinema.film_name AS filmName,\n" +
            "\t\tinfo.film_en_name AS filmEnName,\n" +
            "\t\tcinema.img_address AS imgAddress,\n" +
            "\t\tinfo.film_score AS score,\n" +
            "\t\tinfo.film_score_num AS scoreNum,\n" +
            "\t\tcinema.film_box_office AS totalBox,\n" +
            "\t\t(SELECT GROUP_CONCAT(c.show_name SEPARATOR ',')\n" +
            "\t\tFROM mooc_cat_dict_t c \n" +
            "\t\tWHERE FIND_IN_SET(c.UUID,((SELECT REPLACE(TRIM(BOTH '#' FROM t.film_cats),'#',',') FROM mooc_film_t t WHERE t.UUID = cinema.UUID )))) AS info01,\n" +
            "\t\tCONCAT( (SELECT s.show_name FROM mooc_source_dict_t s WHERE s.UUID = cinema.film_source) ,' / ',info.film_length ,'分钟') AS info02 ,\n" +
            "\t\tCONCAT( DATE_FORMAT(cinema.film_time,'%Y-%m-%d') ,' / ',((SELECT s.show_name FROM mooc_source_dict_t s WHERE s.UUID = cinema.film_source)) ,' 上映 ') AS info03\n" +
            "FROM mooc_film_t cinema , mooc_film_info_t info\n" +
            "WHERE cinema.UUID = info.film_id \n" +
            "AND cinema.film_name LIKE CONCAT('%',#{filmName},'%') ")
    FilmDetailVo getFilmDetailByName(@Param("filmName") String filmName);

    @Select("SELECT \n" +
            "\t\tcinema.uuid AS filmId,\n" +
            "\t\tcinema.film_name AS filmName,\n" +
            "\t\tinfo.film_en_name AS filmEnName,\n" +
            "\t\tcinema.img_address AS imgAddress,\n" +
            "\t\tinfo.film_score AS score,\n" +
            "\t\tinfo.film_score_num AS scoreNum,\n" +
            "\t\tcinema.film_box_office AS totalBox,\n" +
            "\t\t(SELECT GROUP_CONCAT(c.show_name SEPARATOR ',')\n" +
            "\t\tFROM mooc_cat_dict_t c \n" +
            "\t\tWHERE FIND_IN_SET(c.UUID,((SELECT REPLACE(TRIM(BOTH '#' FROM t.film_cats),'#',',') FROM mooc_film_t t WHERE t.UUID = cinema.UUID )))) AS info01,\n" +
            "\t\tCONCAT( (SELECT s.show_name FROM mooc_source_dict_t s WHERE s.UUID = cinema.film_source) ,' / ',info.film_length ,'分钟') AS info02 ,\n" +
            "\t\tCONCAT( DATE_FORMAT(cinema.film_time,'%Y-%m-%d') ,' / ',((SELECT s.show_name FROM mooc_source_dict_t s WHERE s.UUID = cinema.film_source)) ,' 上映 ') AS info03\n" +
            "FROM mooc_film_t cinema , mooc_film_info_t info\n" +
            "WHERE cinema.UUID = info.film_id AND cinema.UUID = #{uuid} ")
    FilmDetailVo getFilmDetailById(@Param("uuid") String uuid);

}
